﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Caviar.SharedKernel.Entities.IM
{
    public class UserTopic : SysUseEntity
    {
        /// <summary>
        /// 用户
        /// </summary>
        public User User { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        public int UserId { get; set; }

        /// <summary>
        /// 朋友
        /// </summary>
        public Friend Friend { get; set; }

        /// <summary>
        /// 朋友ID
        /// </summary>
        public int? FriendId { get; set; }

        /// <summary>
        /// 主题
        /// </summary>
        public Topic Topic { get; set; }

        /// <summary>
        /// 主题ID
        /// </summary>
        public int TopicId { get; set; }

        /// <summary>
        /// 订阅主题
        /// </summary>
        public string Subscribe { get; set; }

        /// <summary>
        /// 发布主题
        /// </summary>
        public string Publish { get; set; }

        /// <summary>
        /// 取消订阅
        /// </summary>
        public bool IsUnsubscribe { get; set; }

        /// <summary>
        /// 取消发布
        /// </summary>
        public bool IsUnpublish { get; set; }

        public void CreateSubscribeOrPublishTitle(string oneselfClientId = null, string othersClientId = null, bool isAllRelace = false)
        {
            if (oneselfClientId != null) 
            {
                Publish = Publish?.Replace("{client_id_oneself}", oneselfClientId);
                Subscribe = Subscribe?.Replace("{client_id_oneself}", oneselfClientId);
            }
            if (othersClientId != null) 
            {
                Publish = Publish?.Replace("{client_id_others}", othersClientId);
                Subscribe = Subscribe?.Replace("{client_id_others}", othersClientId);

                if (isAllRelace)
                {
                    Publish = Publish?.Replace("+", othersClientId);
                    Subscribe = Subscribe?.Replace("+", othersClientId);
                }
            }              
        }
    }
}
